<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/22
 * Time: 23:17
 */

namespace app\shared\logic;


use app\shared\model\Area;
use app\shared\model\City;
use app\shared\model\Province;
use think\facade\Cache;

class Location
{
    private static $model = [];

    public function __construct()
    {
        self::$model = [
            'province' => new Province(),
            'city'     => new City(),
            'area'     => new Area(),

        ];
    }

    public static function get_pca()
    {
        Cache::clear('pca');
//        $pca = Cache::get('pca');
//        if (!empty($pca)) return $pca;
        $pca = [
            'province_list' => self::get_province(),
            'city_list'     => self::get_city(),
            'county_list'     => self::get_area(),
        ];
        Cache::set('pca', $pca, 3600);
        return $pca;
    }

    public static function get_province()
    {
        return self::$model['province']->allByColumn(false, false, 'province_id ASC');
    }

    public static function get_city()
    {
        return self::$model['city']->allByColumn(false, false, 'city_id ASC');
    }

    public static function get_area()
    {
        return self::$model['area']->allByColumn(false, false, 'area_id ASC');
    }
}